<template>
  <div class="home" :ref="homeRef" @scroll="handleScroll">
    <div id="top" ref="top"></div>
    <div class="home-banner">
      <div class="home-banner-carousel">
        <el-carousel :interval="4000" type="card" height="400px">
          <el-carousel-item
            v-for="item in urlList"
            :key="item"
            class="carousel-item"
          >
            <img class="carousel-img" :src="item" alt="" />
          </el-carousel-item>
          <!--          <el-carousel-item v-for="item in (store?.config?.carousel||[])" :key="item" class="carousel-item">-->
          <!--            &lt;!&ndash;          <h3 text="2xl" justify="center">{{ item }}</h3>&ndash;&gt;-->
          <!--            <img style="height: 100%" :src="`/api/files/${item}`" alt="">-->
          <!--          </el-carousel-item>-->
        </el-carousel>
      </div>
      <div class="home-banner-aside">
        <div class="block">
          <div
            class="fs-move-cover_bg"
            style="
              background-image: url('http://pic.fasyncsy.com.cn/coverPic/5.png');
            "
          ></div>
        </div>
        <div class="block">
          <div
            class="fs-move-cover_bg"
            style="background-image: url('https://pic.rmb.bdstatic.com/bjh/1541cacc39f4a9cee0c17d6fcc5217be9794.jpeg@h_1280')"
          ></div>
        </div>
      </div>
    </div>
    <div class="home-content">
      <HomeLeft />
      <HomeCenter ref="centerRef" a="123" />
      <HomeRight />
    </div>
    <div
      :class="{ backTop: true, backActive: backStatus }"
      @click="toTop"
    ></div>
  </div>
</template>
<script setup lang="ts">
// import { storeToRefs } from "pinia";
// import useUserStore from "@/store/modules/userInfo.ts";
import HomeLeft from "~/components/home/HomeLeft.vue";
import HomeRight from "~/components/home/HomeRight.vue";
import HomeCenter from "~/components/home/HomeCenter.vue";
// import HomeCenter from "./HomeCenter.vue";
// import HomeRight from "./HomeRight.vue";
import { ref } from "vue";

const res = await useFetch("/api/home?param1=abcd", {
  method: "GET",
  headers: { "Content-Type": "application/json" },
});
console.log("客户端接收get返回值", res.data);

// const store = storeToRefs(useUserStore()).userInfo.value
const backStatus = ref(false);
const homeRef = ref();
const centerRef = ref<any>(null);
const urlList = ref([
  "https://img1.baidu.com/it/u=1972034828,1599353701&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500",
  "https://img0.baidu.com/it/u=1585246486,101808804&fm=253&fmt=auto&app=120&f=JPEG?w=889&h=500",
  "https://img1.baidu.com/it/u=783663623,2703450222&fm=253&fmt=auto&app=120&f=JPEG?w=889&h=500",
  "https://b0.bdstatic.com/7f15597d49b4e8f7f2d61e148b48b524.jpg@h_1280",
  "https://img0.baidu.com/it/u=1529517484,3708428627&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500",
  "https://nimg.ws.126.net/?url=http%3A%2F%2Fdingyue.ws.126.net%2F2021%2F0824%2Fb3b8a010j00qybyxa000ic000dw007tm.jpg&thumbnail=660x2147483647&quality=80&type=jpg",
  'https://img1.baidu.com/it/u=1869429831,2260078600&fm=253&fmt=auto&app=120&f=JPEG?w=625&h=344'
]);
const top = ref<HTMLDivElement | null>(null);
const handleScroll = (e: any) => {
  backStatus.value = e.target.scrollTop > 400;
  const { scrollTop, clientHeight, scrollHeight } = e.target;
  const bottom = scrollHeight - clientHeight - scrollTop;
  if (bottom <= 10) {
    console.log(centerRef.value);
    if (centerRef.value.scrollBottom) {
      centerRef.value.scrollBottom();
    } else if (centerRef.value._.exposed.scrollBottom) {
      centerRef.value._.exposed.scrollBottom();
    }
    // getCardList();
  }
};
const clickItem = () => {
  console.log(centerRef, homeRef);
};
const toTop = () => {
  top.value&&top.value.scrollIntoView({ behavior: "smooth" });
  // document.getElementById("top").scrollIntoView({ behavior: "smooth" });
};
</script>

<style scoped lang="scss">
@keyframes bgMove {
  0% {
    background-position: 0 0;
  }

  20%,
  60% {
    transform: scale(1);
  }
  40% {
    transform: scale(1.2);
  }
  100% {
    background-position: 100% 100%;
  }
}

@keyframes timerTransition {
  0% {
    transform: translateY(-200%);
  }

  100% {
    transform: translateY(0);
  }
}

.home {
  position: relative;
  width: 100%;
  height: 100vh;
  padding-bottom: 50px;
  background: #f4f5f7;
  overflow-y: auto;

  .home-banner {
    position: relative;
    display: grid;
    grid-template-columns: 1fr 380px;
    grid-template-rows: 1fr;
    grid-gap: 10px; /*上下左右间隔*/
    width: 96%;
    left: 2%;
    top: 2%;
    height: 400px;
    margin-bottom: 20px;

    .home-banner-carousel {
      border-radius: 10px;
      border: 3px solid #fff;
      height: 100%;
      box-sizing: border-box;
      box-shadow: 0 1px 3px #1a1a1a1a;
      .carousel-item {
        display: flex;
        justify-content: center;
        align-items: center;
        .carousel-img {
          max-width: 100%; /* 限制图片最大宽度为容器宽度 */
          max-height: 100%; /* 限制图片最大高度为容器高度 */
          width: auto; /* 保持原始宽度比例 */
          height: auto; /* 保持原始高度比例 */
        }
      }
    }

    .home-banner-aside {
      box-sizing: border-box;
      width: 100%;
      height: 100%;
      display: grid;
      grid-template-rows: 1fr 162px;
      grid-template-columns: 1fr;

      .block {
        width: 100%;
        border: 3px solid #fff;
        border-radius: 10px;
        box-shadow: 0 1px 3px #1a1a1a1a;
        overflow: hidden;
        cursor: pointer;

        .fs-move-cover_bg {
          width: 100%;
          height: 100%;
          background-size: cover;
          animation: bgMove 16s linear infinite alternate;
        }
      }

      .block:first-child {
        margin-bottom: 16px;
      }
    }
  }

  .home-content {
    display: flex;
    // position: relative;
    margin: 2%;
  }

  .backTop {
    position: fixed;
    cursor: pointer;
    right: 30px;
    top: 0;
    z-index: 999;
    width: 70px;
    height: 900px;
    transition: all 0.6s;
    transform: translateY(-100%);
    background: url()
      no-repeat;
  }

  .backActive {
    transform: translateY(-50%);
  }
}
</style>
